<?php
/**
 * Created by PhpStorm.
 * User: MRPHAN
 * Date: 9/27/2014
 * Time: 11:23 PM
 */
namespace Library\Helper;
use Phalcon\Mvc\User\Component;
use Common\Models\Videos\VideoCategory;


class Helper extends Component
{
    /*
     * Create Menu Category
     */
    public function getMenu($parent_id)
    {
        //$menu =  VideoCategory::find('parent_id = ' . intval($parent_id));

        $menu =  VideoCategory::find(array(
            'parent_id = ' . intval($parent_id),
            'order' => 'position ASC'        
        ));

        if(count($menu) > 0){
            return $menu;
        }

    }

    /*
     * Show gender
     */
    public function getGender($gender){
        $msg = '';
        switch($gender){
            case 0:
                $msg = 'Khác';
                break;
            case 1:
                $msg = 'Nữ';
                break;
            case 2:
                $msg = 'Nam';
                break;
        }
        return $msg;
    }
    /*
     * show type of artist
     */
    public  function getTypeOfArtist($type){
        $msg = '';
        switch($type){
            case 1:
                $msg = 'Diễn Viên';
                break;
            case 2:
                $msg = 'Đạo Diễn';
                break;
        }
        return $msg;
    }
    public function resultVideo($total,$key){
        return 'Có '.$total.' phim được tìm thấy theo từ khóa '."'$key'";
    }
    public function getActiveTabSearch($param,$sort){
        return $param==$sort?'class="active"':'';
    }

    public function getStatus($status)
    {
        switch($status)
        {
            case 'A':
                return 'Hoạt động';
                break;
            case 'D':
                return 'Vô hiệu hóa';
                break;
            case 'H':
                return 'Ẩn';
                break;
            case 'W':
                return 'Đang chờ duyệt';
                break;
            default:
                return 'Không xác định';
                break;
        }
        return 'Không xác định';
    }

    public function getPathImageFromImageLink($imageLink , $thumnail)
    {
        $pathImage = '';
        if($imageLink)
        {
            if($imageLink->images)
            {
                $pathImage = $imageLink->images->getImagePath();
            }
        }
        if($pathImage)
        {
            if($thumnail)
            {
                $pathImage = $this->constant->pathUploadImageThubnail . $thumnail . '/' .$pathImage;
            }
            else
            {
                $pathImage = $this->constant->pathUploadImage . $pathImage;
            }
        }
        else
        {
            $pathImage = 'http://image.mp3.zdn.vn/content/2/6/2698cb09e9b5fddee387c9cba124910d_1413518897.jpg';
        }

        return $pathImage;
    }

    public function getPathSourceVideoFile($videoFile)
    {

        switch($videoFile->getSourceServer())
        {
            case 'Y'://Youtube
            case 'D'://dailymotion
            case 'V'://Vimeo
                return $videoFile->getLinkSourceServer();
            break;

            case 'J':
                return $this->url->get($this->constant->pathVideoFile . $videoFile->getFilePath());
            break;
        }
    }
}